Skip to content

(fix) cqlengine: handle missing table metadata after schema change in sync_table#11

Open
mykaul wants to merge 2 commits into
masterfrom
fix/sync-table-metadata-keyerror
Open

(fix) cqlengine: handle missing table metadata after schema change in sync_table#11
mykaul wants to merge 2 commits into
masterfrom
fix/sync-table-metadata-keyerror

Conversation

@mykaul

@mykaul mykaul commented Mar 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • Wrap table metadata lookups in _sync_table() and _get_table_metadata() with try/except KeyError, forcing a targeted cluster.refresh_table_metadata() on miss and retrying once
  • Raises a descriptive CQLEngineException (instead of a bare KeyError) if the table is still not present after the forced refresh
  • Follows the same defensive pattern already used in _sync_type() (which calls cluster.refresh_user_type_metadata() after CREATE TYPE)

Root cause

After CREATE TABLE or ALTER TABLE, the local metadata cache may not yet contain the new table if schema agreement timed out or the automatic metadata refresh was skipped. Both _sync_table() (line 273) and _get_table_metadata() (line 435) unconditionally accessed cluster.metadata.keyspaces[ks].tables[table], which raised KeyError in this race condition.

This manifested as a flaky CI failure in TestContainsOperator.setUpClasssync_table(IndexedTestModel).

Tests

  • Added unit tests (tests/unit/cqlengine/test_management.py) for _get_table_metadata verifying: immediate hit (no refresh), successful retry after refresh, and failure after refresh
  • All existing unit tests pass

@mykaul mykaul force-pushed the fix/sync-table-metadata-keyerror branch from d937ce8 to 6f1be93 Compare March 14, 2026 09:06
… sync_table

After CREATE TABLE or ALTER TABLE, the local metadata cache may not yet
contain the new table if schema agreement timed out or the automatic
metadata refresh was skipped.  _sync_table() and _get_table_metadata()
unconditionally accessed cluster.metadata.keyspaces[ks].tables[table],
which raised KeyError in this case.

Wrap both lookups in try/except KeyError.  On miss, force a targeted
cluster.refresh_table_metadata() call and retry once.  If the table is
still not present after the forced refresh, raise a descriptive
CQLEngineException instead of a bare KeyError.

This follows the same defensive pattern already used in _sync_type(),
which calls cluster.refresh_user_type_metadata() after CREATE TYPE.

Add unit tests for _get_table_metadata verifying: immediate hit (no
refresh), successful retry after refresh, and failure after refresh.
@mykaul mykaul force-pushed the fix/sync-table-metadata-keyerror branch from 6f1be93 to d5c3f18 Compare March 14, 2026 09:18
Drop the detailed description from the test_management.py docstring,
keeping only the general module-level summary.
@mykaul mykaul force-pushed the fix/sync-table-metadata-keyerror branch from 30a8fd7 to 59408e4 Compare April 2, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant